package com.jxwifi.cloud.quickclean.popwindow;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.idroid.utils.NoDoubleClickListener;
import com.jxwifi.cloud.quickclean.R;
import com.jxwifi.cloud.quickclean.app.StateUtils;
import com.jxwifi.cloud.quickclean.utils.ToastUtils;
import com.popwindow.BasicPopmodule;

import java.text.DecimalFormat;

public class PopPayDepositModule extends BasicPopmodule {

    private String TAG = this.getClass().getSimpleName();
    private Context mContext;
    private PopPayListener mPoplistener;
    private double mDeposit; //需要支付的金额
    private String mPayTitle;

    private String mAlipayOrWeixin= StateUtils.ALIPAY;

    public PopPayDepositModule(Context context,double deposit,String paytitle,PopPayListener l){
        this.mContext=context;
        this.mPoplistener=l;
        this.mDeposit=deposit;
        this.mPayTitle=paytitle;
        initView();
    }

    @Override
    public void setPopwindow(PopupWindow pop) {
        mPopwindows = pop;
    }

    @Override
    public View getView() {
        return mContentView;
    }

    private void initView() {
        mContentView = LayoutInflater.from(mContext).inflate(R.layout.pop_pay_deposit_module, new LinearLayout(mContext), false);
        setListener();
    }

    public void setListener() {
        View mVwPopBlank=(View)mContentView.findViewById(R.id.vw_pop_blank);
        TextView mTvOrderStartsCancelEvaluate=(TextView)mContentView.findViewById(R.id.tv_order_starts_cancel_evaluate);
        TextView mTvOrderStartsCenter=(TextView)mContentView.findViewById(R.id.tv_order_starts_center);
        final TextView mTvPayOrderPrice=(TextView)mContentView.findViewById(R.id.tv_pay_order_price);
        RelativeLayout mRelPayCoupon1=(RelativeLayout)mContentView.findViewById(R.id.rel_pay_coupon1);//支付宝支付
        final ImageView mImgPayOrderOfAlipay=(ImageView)mContentView.findViewById(R.id.img_pay_order_of_alipay);
        RelativeLayout mRelPayOrderOfWeixin=(RelativeLayout)mContentView.findViewById(R.id.rel_pay_order_of_weixin);//微信支付
        final ImageView mImgPayOrderOfWeixin=(ImageView)mContentView.findViewById(R.id.img_pay_order_of_weixin);
        TextView mTvPayPayment=(TextView)mContentView.findViewById(R.id.tv_pay_payment);
        mTvOrderStartsCenter.setText(mPayTitle);
        //保留后两位，去掉不要的尾数，不四舍五入
        DecimalFormat df = new DecimalFormat("#0.00");
        mTvPayOrderPrice.setText("\u00A5"+df.format(mDeposit));
        //Log.i(TAG,"mDeposit = "+mDeposit+" 显示金额 = "+"\u00A5"+df.format(mDeposit));
        mVwPopBlank.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                mPopwindows.dismiss();
            }
        });

        mTvOrderStartsCancelEvaluate.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                mPopwindows.dismiss();
            }
        });

        mRelPayCoupon1.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                mImgPayOrderOfAlipay.setBackgroundResource(R.mipmap.icon_alipay_right);
                mImgPayOrderOfWeixin.setBackgroundResource(R.mipmap.icon_notchecked);
                mAlipayOrWeixin=StateUtils.ALIPAY;
            }
        });

        mRelPayOrderOfWeixin.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                /*Toast toast = Toast.makeText(mContext, "微信支付功能暂未开通", Toast.LENGTH_SHORT);
                ToastUtils.showMyToast(toast, 3000);*/
                mImgPayOrderOfAlipay.setBackgroundResource(R.mipmap.icon_notchecked);
                mImgPayOrderOfWeixin.setBackgroundResource(R.mipmap.icon_alipay_right);
                mAlipayOrWeixin=StateUtils.WEIXIN;
            }
        });

        mTvPayPayment.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                mPoplistener.getPayOrder(mAlipayOrWeixin,mTvPayOrderPrice.getText().toString());
                mPopwindows.dismiss();
            }
        });
    }

    public interface PopPayListener{
        void getPayOrder(String PayType, String PayPrice);
    }
}
